package controllers;

import java.io.IOException;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import systems.ConfigSystem;

import debugs.DomainDebug;

import admin.models.DomainModel;
import admin.models.MetaSeoModel;

import entities.Domain;
import entities.MetaSeo;
import entities.SiteConfig;

public class WhoisServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		
		TreeMap check = new TreeMap();
		String domainName = (String) request.getParameter("domain");
		
		if (domainName != null && domainName.isEmpty()) {
			response.sendRedirect("/msg/page-not-found");
			return;
		}
		
		DomainModel domainModel = DomainModel.getInstance();
		Domain domain = null;
		if (domainName != null) {
			domain = domainModel.get(domainName);
			DomainDebug.debug(domain);
		} else {
			domainName = "";
		}
		
		//Set seo content
        MetaSeoModel metaseoModel = MetaSeoModel.getInstance();
        MetaSeo metaseo = metaseoModel.get("whois");
		
		//Cache header
		response.addHeader("Cache-Control", "public, max-age=60000");
		
		request.setAttribute("domain", domain);
		request.setAttribute("domainName", domainName);
		request.setAttribute("check", check);
		request.setAttribute("metaseo", metaseo);
		try {
			request.getRequestDispatcher("/demo/pages/whois_info.jsp").forward(request, response);
		} catch (ServletException e) {
			e.printStackTrace();
		}
	}
}
